home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group95a.txt / 000045_icon-group-sender _Sat Feb 4 20:43:44 1995.msg < prev    next >
Internet Message Format  |  1995-02-09  |  7KB

  1. Received: by cheltenham.cs.arizona.edu; Sat, 4 Feb 1995 19:40:58 MST
  2. Date: Sat, 4 Feb 95 20:43:44 CST
  3. From: goer@mithra-orinst.uchicago.edu (Richard L. Goerwitz)
  4. Message-Id: <9502050243.AA08637@mithra-orinst.uchicago.edu>
  5. To: icon-group@cs.arizona.edu
  6. Subject: more Icon, CGI
  7. Errors-To: icon-group-errors@cs.arizona.edu
  8.  
  9. Another invitation to Icon users interested in the Web and CGI
  10. scripts....
  11.  
  12. Not all clients implement mailto, so if you want, say, for people
  13. reading an article you wrote to be able to mail you comments from
  14. a form, you need a form and a CGI script to do this.  Here are ex-
  15. amples of both.
  16.  
  17. Appended below, immediately after my signature, is a short HTML
  18. form.  After that is an Icon program that does the mailing.  It is
  19. simple, and probably could be improved in many ways.  I provide it
  20. here merely as an example.
  21.  
  22. Naturally, the mailing addresses and hard-coded system files will
  23. need to be changed.  Name the form anything you want.  Compile the
  24. Icon program and put it into the cgi-bin directory.  I recall when
  25. I first installed the executable running into problems with version
  26. 8 of Icon.  Version 9, though, worked fine.
  27.  
  28. Anyone wanting to take a look at how the form works can just jump
  29. to the end of one of the following documents.  I tend to put an
  30. HREF to the comments form at the end of docs I place online.
  31.  
  32.    http://oi.uchicago.edu:1080/pub/stuff/accents/accents.html
  33.    http://oi.uchicago.edu:1080/pub/papers/goerwitz/sbl94talk/sbl94talk.html
  34.  
  35. Richard Goerwitz
  36.  
  37.  
  38. =============================== cut here =========================
  39. <HTML>
  40.  
  41. <HEAD>
  42.   <TITLE>Feedback Form</TITLE>
  43. </HEAD>
  44.  
  45. <BODY>
  46.  
  47.   <H1>Feedback Form</H1>
  48.  
  49.   <P>This form offers a quick, easy way of forwarding comments back to me.
  50.     Just fill out the fields below, and then click on the "mail comments"
  51.     button near the end.
  52.   </P>
  53.  
  54.   <FORM METHOD="POST" ACTION="http://oi.uchicago.edu:1080/cgi-bin/forward_comments">
  55.   <P>E-mail: <INPUT NAME="sender"> Your name: <INPUT NAME="name"></P>
  56.   <P>Paper title:  <INPUT NAME="title" SIZE=50></P>
  57.   <P>Comments you would like to offer:</P>
  58.     <TEXTAREA NAME="comments" ROWS=8 COLS=60></TEXTAREA>
  59.   <P><INPUT TYPE="submit" VALUE="mail comments to goer@midway.uchicago.edu"></P>
  60.   </FORM>
  61.  
  62.   <P>If you prefer, send your comments to <A HREF=
  63.     "http://oi.uchicago.edu:1080/~goer/cvrlg.html">me</A> manually, using your
  64.     local system mailer
  65.   </P>
  66.  
  67.   <HR>
  68.   <ADDRESS>Richard L. Goerwitz, goer@midway.uchicago.edu</ADDRESS>
  69.  
  70. </BODY>
  71.  
  72. </HTML>
  73.  
  74. ================================ cut here ==========================
  75.  
  76. ############################################################################
  77. #
  78. #    File:     forward_comments.icn
  79. #
  80. #    Subject:  Program to forward comments sent via a fillout form
  81. #
  82. #    Author:   Richard L. Goerwitz
  83. #
  84. #    $Revision$
  85. #
  86. ############################################################################
  87.  
  88. $define MYADDRESS "goer@midway.uchicago.edu"
  89.  
  90. procedure main(a)
  91.  
  92.     local i, cl, n, name_tbl, f, sender, comments, nam, subj
  93.  
  94.     cl := integer(getenv("CONTENT_LENGTH"))
  95.     name_tbl := table()
  96.  
  97.     #
  98.     # output a minimal header, terminated by two newlines
  99.     #
  100.     write("Content-type: text/html\x0A\x0A")
  101.  
  102.     #
  103.     # check that the request is correctly formatted; output
  104.     # error message if it's not
  105.     #
  106.     getenv("REQUEST_METHOD") == "POST" | {
  107.         writes("<P>error:  METHOD must = \"POST\"</P>")
  108.         exit(1)
  109.     }
  110.     getenv("CONTENT_TYPE") == "application/x-www-form-urlencoded" | {
  111.         writes("<P>error:  this script is for decoding form results only</P>")
  112.         exit(1)
  113.     }
  114.  
  115.     #
  116.     # enter name=value lines as key/value pairs in name_tbl
  117.     #
  118.     while line := makeline(&input, "&", cl) do {
  119.     line := unescape_url(map(line, "+", " "))
  120.     line ? {
  121.         n := tab(find("="))
  122.         move(1)
  123.         if not (/name_tbl[n] := tab(0)) then {
  124.         writes("<P>error:  duplicate field name, ", n, "</P>")
  125.         exit(1)
  126.         }
  127.     }
  128.     }
  129.  
  130.     writes("<HTML><HEAD><TITLE>Feedback Submission Results</TITLE></HEAD>")
  131.     writes("<BODY>")
  132.     writes("<H1>Feedback submission results:</H1>")
  133.  
  134.     #
  135.     # Collect the mailing address of the sender & his or her comments
  136.     #
  137.     sender   := ("" ~== \name_tbl["sender"])    | {
  138.     writes("<P>error:  you forgot to give your e-mail address</P>")
  139.     exit(2)
  140.     }
  141.     comments := ("" ~== \name_tbl["comments"])    | {
  142.     writes("<P>error:  no comments found!</P>")
  143.     exit(2)
  144.     }
  145.     nam   := ("" ~== \name_tbl["name"])        | "(unknown)"
  146.     title := ("" ~== \name_tbl["title"])    | "(unspecified)"
  147.     subj  := "comments from " || nam || " (" || sender || ") regarding " || title
  148.  
  149.     #
  150.     # Send off comments using system mailer
  151.     #
  152.     f := open("Mail -s '"|| subj ||"' "|| MYADDRESS, "pw") | {
  153.     writes("<P>error:  mailer offline</P>")
  154.     exit(3)
  155.     }
  156.     write(f, comments)
  157.     close(f)
  158.  
  159.     #
  160.     # Report results to the comment-er
  161.     #
  162.     writes("<P>Your comments have been successfully forwarded.</P>")
  163.     writes("<P>Here is the text of what you sent:</P>")
  164.     writes("<PRE>", comments, "</PRE><HR>")
  165.     writes("<P>Thanks for your input,</P>")
  166.     writes("<P>Richard Goerwitz <ADDRESS>" || MYADDRESS || "</ADDRESS></P>")
  167.     writes("</BODY></HTML>")
  168.  
  169.     exit(0)
  170.  
  171. end
  172.  
  173.  
  174. #
  175. # concatenate series of non-ampersands into lines; stop
  176. # when you have read the number of characters in cl (arg
  177. # 3); stop_c is going to be "&"
  178. #
  179. procedure makeline(f, stop_c, cl)
  180.  
  181.     local line, c
  182.     static c_count
  183.     initial c_count := 0
  184.  
  185.     line := ""
  186.     while c := reads(f) do {
  187.     if (c_count +:= 1) > cl then
  188.         break
  189.         if c == stop_c then
  190.         break
  191.     line ||:= c
  192.     }
  193.     return "" ~== line
  194.  
  195. end
  196.  
  197.  
  198. #
  199. # turn &xx (where xx are hex digits) into an integer;
  200. # output the character with that internal integer value
  201. #
  202. procedure unescape_url(url)
  203.  
  204.     local new_url
  205.  
  206.     new_url := ""
  207.  
  208.     url ? {
  209.     while new_url ||:= tab(find("%")) & move(1) do
  210.         new_url ||:= char(hex(move(2))) | tab(0)
  211.     new_url ||:= tab(0)
  212.     }
  213.  
  214.     return new_url
  215.  
  216. end
  217.  
  218.  
  219. #
  220. # Bob Alexander's hex->integer code (overkill here)
  221. #
  222. procedure hex(s)
  223.  
  224.    local a,c
  225.  
  226.    a := 0
  227.    every c := !map(s) do
  228.        a := ior(find(c,"0123456789abcdef") - 1, ishift(a,4)) | fail
  229.    return a
  230.  
  231. end
  232. #
  233. #
  234. procedure hexstring(i,n,lowercase)
  235.  
  236.    local s, hexchars, sign
  237.  
  238.    i := integer(i) | runerr(101, i)
  239.    sign := ""
  240.    if i = 0 then s := "0"
  241.    else {
  242.        if /n & i < 0 then {
  243.        sign := "-"
  244.        i := -i
  245.        }
  246.        hexchars := if \lowercase
  247.        then "0123456789abcdef"
  248.        else "0123456789ABCDEF"
  249.        s := ""
  250.        until i = (0 | -1) do {
  251.        s := hexchars[iand(i,15) + 1] || s
  252.        i := ishift(i,-4)
  253.        }
  254.    }
  255.    if \n > *s then s := right(s,n,if i >= 0 then "0" else hexchars[16])
  256.  
  257.    return sign || s
  258.  
  259. end